# Contributor: Ian Bashford <ianbashford@gmail.com>
# Maintainer: Ian Bashford <ianbashford@gmail.com>
pkgname=dnscrypt-proxy
pkgver=2.1.5
pkgrel=2
pkgdesc="Tool for securing communications between a client and a DNS resolver"
url="https://dnscrypt.info"
arch="all"
license="ISC"
depends="ca-certificates"
makedepends="go"
install="$pkgname.pre-install"
pkgusers=dnscrypt
pkggroups=dnscrypt
subpackages="$pkgname-setup::noarch $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/DNSCrypt/dnscrypt-proxy/archive/$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.setup
	dnscrypt-proxy.toml
	"
options="!check"
builddir="$srcdir/dnscrypt-proxy-$pkgver/dnscrypt-proxy"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build
}

package() {
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/etc/$pkgname
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/usr/share/$pkgname
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/var/cache/$pkgname
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/var/log/$pkgname
	install -m755 -D dnscrypt-proxy "$pkgdir"/usr/bin/dnscrypt-proxy
	install -Dm 644 "$srcdir"/dnscrypt-proxy.toml "$pkgdir"/etc/$pkgname/dnscrypt-proxy.toml
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	for i in example-*; do
		install -m644 -D "$i" -t "$pkgdir"/usr/share/doc/$pkgname/
	done
}

setup() {
	pkgdesc="Script for setting up dnscrypt proxy"
	depends="sed wget $pkgname=$pkgver-r$pkgrel"

	install -m755 -D "$srcdir"/$pkgname.setup "$subpkgdir"/usr/sbin/setup-dnscrypt
}

sha512sums="
2c9a0e0896483b4453cb3779efd41205be8839e61e17b86701deb91e531676529a82b8859ae0975d121322ec8cc05bdd13a1324b8f56010692e1ac9f36a99d69  dnscrypt-proxy-2.1.5.tar.gz
a1bbcc63d3160e2101096cb06d714422ee85f7cf86a856b53437abb04f23995ac75b2a9d980c6c8e790bd5db350f1e2d6d39093705b0657020323179e5ff2076  dnscrypt-proxy.initd
c001ae39da1b2db71764cab568f9ed18e4de0cea3d1a4e7bd6dd01a5668b81a888ea9eef99de6beac08857ad7f8eb1a32d730e946ac3563e4dcfa27147e35052  dnscrypt-proxy.confd
1c2bd450b1d195bd11d3441017f269904b3eb8ee8ace419f11882679664840b47d32e20c56d190b06dc5d9bb4dea0bfadbc878dcb1272af391b225bae56ad1e7  dnscrypt-proxy.setup
57ef614959b0f5bc72caed0a1b8027984a34b8d8b8abbe9eae531c4d6d98fee136f3852820c71ae858dd98b7039af5c826c88eb4153f4f0d17866db1d206facd  dnscrypt-proxy.toml
"
